package com.example.demo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Slf4j
@Component
public class RequestListener implements ServletRequestListener {
    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {

    }

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
//        ServletRequest servletRequest = servletRequestEvent.getServletRequest();
        HttpServletRequest servletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest();
        HttpSession session = (servletRequest).getSession();

        String remoteAddr = servletRequest.getRemoteAddr();

        log.debug("sessionId:{},remoteAddr:{}", session.getId(), remoteAddr);
    }
}
